﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Common;
using DotNet.Data.Factory;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace DotNet.Data
{
	public class Tab_OrderDal
	{
		IDBHelp db = DBHelp.Create();
		 Hashtable htSyn = Hashtable.Synchronized(new Hashtable());
		StringBuilder strSql = new StringBuilder();

		#region 是否存在该记录
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		/// <param name="orderID">标识列ID</param>
		public bool Exists(int orderID)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select count(1) from [Tab_Order] where orderID=@orderid ");
			htSyn.Add("@orderid", orderID);
			return db.IsExists(strSql.ToString(), htSyn);
		}
		#endregion

		#region 得到该表数据列表
		/// <summary>
		/// 得到该表数据列表
		/// </summary>
		public IList<Tab_Order> GetModel()
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("Select [isProcess],[orderID],[orderDate],[orderEmail],[orderAddress],[orderContent],[orderCustomerName],[orderTel],[orderPhone] FROM [Tab_Order]");
			 return getTab_OrderBySql(strSql.ToString());
		}
		#endregion

		#region 根据标识列查询实体
		/// <summary>
		/// 根据标识列查询实体
		/// </summary>
		/// <param name="orderID">标识列ID</param>
		/// <returns></returns>
		public Tab_Order GetModel(int orderid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select [isProcess],[orderID],[orderDate],[orderEmail],[orderAddress],[orderContent],[orderCustomerName],[orderTel],[orderPhone] FROM [Tab_Order]");
			strSql.Append(" where orderID=@orderid ");
			htSyn.Add("@orderid", orderid);
			DataTable dt = db.GetDataTable(strSql.ToString(), htSyn);
			Tab_Order tab_orderModel = new Tab_Order();
			if (dt.Rows.Count > 0)
			{
				tab_orderModel.isProcess=Convert.ToBoolean(dt.Rows[0]["isProcess"]);
				tab_orderModel.orderDate=dt.Rows[0]["orderDate"].ToString();
				tab_orderModel.orderEmail=dt.Rows[0]["orderEmail"].ToString();
				tab_orderModel.orderAddress=dt.Rows[0]["orderAddress"].ToString();
				tab_orderModel.orderContent=dt.Rows[0]["orderContent"].ToString();
				tab_orderModel.orderCustomerName=dt.Rows[0]["orderCustomerName"].ToString();
				tab_orderModel.orderTel=dt.Rows[0]["orderTel"].ToString();
				tab_orderModel.orderPhone=dt.Rows[0]["orderPhone"].ToString();
			}
			return tab_orderModel;
		}
		#endregion

		#region 修改信息
		/// <summary>
		/// 修改信息
		/// </summary>
		/// <param name="Tab_Order">实体</param>
		/// <returns></returns>
		public bool Update(Tab_Order tab_orderModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("update [Tab_Order] set ");
			strSql.Append("[isProcess]=@isprocess,");
			strSql.Append("[orderDate]=@orderdate,");
			strSql.Append("[orderEmail]=@orderemail,");
			strSql.Append("[orderAddress]=@orderaddress,");
			strSql.Append("[orderContent]=@ordercontent,");
			strSql.Append("[orderCustomerName]=@ordercustomername,");
			strSql.Append("[orderTel]=@ordertel,");
			strSql.Append("[orderPhone]=@orderphone");

			strSql.Append(" where orderID=@orderid ");
			htSyn.Add("@isprocess", tab_orderModel.isProcess);
			htSyn.Add("@orderid", tab_orderModel.orderID);
			htSyn.Add("@orderdate", tab_orderModel.orderDate);
			htSyn.Add("@orderemail", tab_orderModel.orderEmail);
			htSyn.Add("@orderaddress", tab_orderModel.orderAddress);
			htSyn.Add("@ordercontent", tab_orderModel.orderContent);
			htSyn.Add("@ordercustomername", tab_orderModel.orderCustomerName);
			htSyn.Add("@ordertel", tab_orderModel.orderTel);
			htSyn.Add("@orderphone", tab_orderModel.orderPhone);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 删除信息
		/// <summary>
		/// 删除信息
		/// </summary>
		/// <param name="orderID">标识列ID</param>
		/// <returns></returns>
		public bool Delete(int orderID)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("delete from [Tab_Order] where orderID=@orderid");
			htSyn.Add("orderid", orderID);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 添加信息
		/// <summary>
		/// 添加信息
		/// </summary>
		/// <param name="Tab_Order">实体</param>
		/// <returns></returns>
		public bool Insert(Tab_Order tab_orderModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("insert into [Tab_Order]([isProcess],[orderDate],[orderEmail],[orderAddress],[orderContent],[orderCustomerName],[orderTel],[orderPhone]) values (@isprocess,@orderdate,@orderemail,@orderaddress,@ordercontent,@ordercustomername,@ordertel,@orderphone)");
			htSyn.Add("@isprocess", tab_orderModel.isProcess);
			htSyn.Add("@orderdate", tab_orderModel.orderDate);
			htSyn.Add("@orderemail", tab_orderModel.orderEmail);
			htSyn.Add("@orderaddress", tab_orderModel.orderAddress);
			htSyn.Add("@ordercontent", tab_orderModel.orderContent);
			htSyn.Add("@ordercustomername", tab_orderModel.orderCustomerName);
			htSyn.Add("@ordertel", tab_orderModel.orderTel);
			htSyn.Add("@orderphone", tab_orderModel.orderPhone);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 根据SQL语句获取集合
		/// <summary>
		///根据SQL语句获取集合
		/// </summary>
		/// <param name="strSql">sql语句</param>
		public IList<Tab_Order> getTab_OrderBySql(string strSql)
		{
			IList<Tab_Order> list = new List<Tab_Order>();
			DataTable dt = db.GetDataTable(strSql);
			if (dt.Rows.Count > 0)
			{
				foreach (DataRow dr in dt.Rows)
				{
					Tab_Order tab_orderModel = new Tab_Order();
					tab_orderModel.isProcess= Convert.ToBoolean(dr["isProcess"]);
					tab_orderModel.orderID= Convert.ToInt32(dr["orderID"]);
					tab_orderModel.orderDate=dr["orderDate"].ToString();
					tab_orderModel.orderEmail=dr["orderEmail"].ToString();
					tab_orderModel.orderAddress=dr["orderAddress"].ToString();
					tab_orderModel.orderContent=dr["orderContent"].ToString();
					tab_orderModel.orderCustomerName=dr["orderCustomerName"].ToString();
					tab_orderModel.orderTel=dr["orderTel"].ToString();
					tab_orderModel.orderPhone=dr["orderPhone"].ToString();
					list.Add(tab_orderModel);
				}
			}
			return list;
		}
		#endregion
	}
}
